/**
 * Created by Administrator on 2018/1/13.
 */
/**
 * Created by Administrator on 2017/12/2.
 */
define(function(require, exports, module) {
    var $=require('zepto');
        api=require('api');
        cn=require('conment');
        cook=require('cookie');
    var tel=/^1[3|4|5|7|8]\d{9}$/;
    var pswd=/^[0-9A-Za-z]+$/;
    module.exports = {
        rex:{
            shineCard:/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/, //身份证
            revemp:/^[\u4E00-\u9FA5]+$/,//用户名!(/^[0-9A-Za-z]+$/)[\u4e00-\u9fa5]
            nickName:/^[A-Za-z0-9\u4e00-\u9fa5]{2,6}$/,
            msg:'',
            keyObj:null,
            bankCord:''
        },
        relname:function(){
            const _this=this;
            const x=$.trim($('#xName').val())
            const s=$.trim($('#ipCard').val())
            // console.log(_this.rexName(x,s))
            if(!_this.rexName(x,s)){
                cn.alert(_this.rex.msg)
                return false
            }else {
                cn.Ajax(api.certificate,{
                    name:encodeURI(x),
                    idNum:s,
                },function(d){
                    if(d.flag==1){
                        cn.alert(d.message);
                        setTimeout(function () {
                            window.location.href='/view/setting.html'
                        },1000)
                    }else {
                        cn.alert(d.message);
                    }

                    // console.log(d)
                },'post')
            }
        },
        /* 实名认证
            * **/
        rexName:function(x,s){
        return x==''?(this.rex.msg='请输入真实姓名',false)
            :!(this.rex.revemp).test(x)?(this.rex.msg='姓名输入格式有误',false)
                :s==''?(this.rex.msg='请输入身份证号码',false)
                    :!(this.rex.shineCard).test(s)?(this.rex.msg='身份证输入格式有误',false):true
         },


        nickName:function(x,s){
            return x==''?(this.rex.msg='请输入昵称',false)
                :!(this.rex.nickName).test(x)?(this.rex.msg='昵称限制：2-6位汉字,数字,字母',false):true
        },


        changeNickName:function () {
            const _this=this;
            const x=$('#xName').val().replace(/\s/g,"")
            // console.log(_this.rexName(x,s))
            if(!_this.nickName(x)){
                cn.alert(_this.rex.msg)
                return false
            }else {
                cn.Ajax(api.chengNickName,{
                    nickname:encodeURI(x),
                },function(d){
                    if(d.flag==1){
                        cn.alert(d.message);
                        setTimeout(function () {
                            window.location.href='/view/user.html'
                        },1000)
                    }else {
                        cn.alert(d.message);
                    }
                },'post')
            }
        },
        init:function(option){
            const _this=this;
            $('.niceName').val(sessionStorage.getItem('nickName'))
            $('#relName_btn').on('click',function () {
                _this.relname()
            });
            $('#changeNickName_btn').on('click',function () {
                _this.changeNickName()
            });
        },


    }
});